
var role='stu';
$('#change_stu').hide();
$('#change_teacher').click(function () {
    $('.hide_box').hide();
    $('#change_stu').show();
    $('#change_teacher').hide();
    role='teacher';
});
$('#change_stu').click(function () {
    $('.hide_box').show();
    $('#change_stu').hide();
    $('#change_teacher').show();
    role='stu'
});

$.post({
    url:'requests/index.php',
    success:function (data) {
        for (var i = 0; i < data.classes.length;i++){
            $("<option/>",{text:data.classes[i].name,value:data.classes[i].num}).appendTo($("select[name='class_name']"));
        }
    }
});

$('#btn_login').click(function () {
    var num=$("input[name='num']").val();
    var psw=$("input[name='psw']").val();
    var class_num=$("select[name='class_name']").val();
    if (check(num,psw)){
        $.post({
            url: 'requests/login.php',
            data: {'num': num, 'psw': $.md5(psw), 'role': role,'class':class_num},
            async:false,
            success: function (data) {
                if (data == "teacher1") {
                    $$.toast('教师登录');
                    window.location.href='../teacher1.0/pages/class.html';
                }
                else if (data == 'stu1') {
                    $$.toast('学生登录');
                    window.location.href='../student/pages/course.html?'+class_num;
                }
                else {
                    $$.toast('登录失败');
                }
            }
        });
    }
    else {
        $$.toast("账号或密码不能为空！","warn");
    }
});
function check(num,psw) {
    if (num ==""||psw==""){
        return false;
    }
    else return true;
}